home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Stolen Data 1
/
Stolen Data 1.adf
/
Source
/
Mouse_bobs.s
< prev
next >
Wrap
Text File
|
1989-11-02
|
7KB
|
346 lines
Incdir Df1:
Include Source/CustomRegisters
;-- CustomRegisters is an include file which defines all the custom
;-- chip registers I use and also creates three macros which make
;-- creating copperlists much easier ( Mov, Wait, Skip )
*************************************************************************
***** Sorry but these examples will only work with DEVPAC II ******
***** despite what I said in the magazine ******
*************************************************************************
Ciaapra = $BFE001 ;CIA port a register, bit 6 is used for
;the left mouse button, and bit 1 toggles
;the power LED which is connected to the
;low pass filter
Oldopenlibrary = -$198 ;Open a library of functions, a pointer
;to the library name is sent in a1,
;ignores the library version no.
Disable = -$78 ;Switch off interrupts,and multitasking
;( taskswitching occurs in the vertical
;blanking interrupt )
Enable = -$7e ;Enable interrupts,including multitasking
Startlist = 38 ;The standard workbench copperlist.
Execbase = 4 ;A pointer to the EXEC library which
;contains all the fundamental operating
;system routines.
Move.l Execbase,a6
Jsr Disable(a6) ;Disable interrupts
Bsr Setup
;------ Wait for Vertical position 1 --------
Wait Move.l Vposr,d2
And.l #$0001ff00,d2
Cmp.l #$00010800,d2
Bne.s Wait
;-- Clear the previous bobs
Lea Xs(pc),a3
Lea Ys(pc),a4
Move Pointer(pc),d6
Moveq #15,d7
Clear_bobs
Move (a3,d6),d0
Move (a4,d6),d1
Bsr Bob_clr
Subq #8,d6
And #$7e,d6
Dbf d7,Clear_bobs
;-- Check the mouse and update the bob position accordingly
Addq #2,Pointer
And #$7e,Pointer
Bsr Mousey
;-- Now plot the bobs in their new positions
Move Pointer(pc),d6
Moveq #15,d7
Draw_bobs
Move (a3,d6),d0
Move (a4,d6),d1
Bsr Bob_draw
Subq #8,d6
And #$7e,d6
Dbf d7,Draw_bobs
Btst #6,Ciaapra ;Have you pressed the left button
Bne.s Wait
;------ Restore old Copper list -----------
Move.l Execbase,a6
Move.l #Grname,a1
Clr.l d0
Jsr Oldopenlibrary(a6) ;Open the graphics library
Move.l d0,a4
Move.l Startlist(a4),Cop1lc ;Restore the old copperlist
Clr.w Copjmp1
Move.w #$83E0,Dmacon
Jsr Enable(a6) ;Re-enable the interrupts
Clr.l d0 ;No return-code errors
Rts
;-------- Setup routine ----------
Setup
Move.w #$8780,Dmacon ;Make sure copper,blitter and other
;DMA is switched on.
Move.w #$0020,Dmacon ;Turn off sprite DMA
Lea Spr0data,a0 ;Now clear all sprite data to eliminate
Moveq #7,d0 ;the lines you occasionaly get if you
Spr_clr ;forget to do this.
Clr.l (a0) ;Clear both data words simultaneously
Addq.l #8,a0
Dbf d0,Spr_clr
;-- Clear the screen
Move.l Bob_scr(pc),a0
Move #$f9f,d0
Clr_scr
Clr.l (a0)+
Dbf d0,Clr_scr
;-- Create the mask
Lea Bob_data(pc),a0
Lea Width(a0),a1
Lea Bob_mask(pc),a2
Lea Width(a2),a3
Move #Length-1,d1
Mask_loop2
Move #Width/2-1,d0
Mask_loop1
Move (a0)+,d2
Or (a1)+,d2
Move d2,(a2)+
Move d2,(a3)+
Dbf d0,Mask_loop1
Lea Width(a0),a0
Lea Width(a1),a1
Lea Width(a2),a2
Lea Width(a3),a3
Dbf d1,Mask_loop2
;-- Reset the mouse counters
Move Joy0dat,d0
Move d0,d1
And #$ff,d0
Move d0,Last_posx
Lsr #8,d1
Move d1,Last_posy
Move.l #Clstart,Cop1lc ;Start up my own copperlist
Clr Copjmp1
Rts
Blit_wait
Btst #14,Dmaconr
Bne.s Blit_wait
Rts
;--------- Mouse routine ----------
Last_posy Dc.w 0
Last_posx Dc.w 0
Mousey
Move Last_posy(pc),d0
Move Joy0dat,d1
Lsr #8,d1
Move d1,Last_posy
Sub d1,d0
Bmi.s Negative
Cmp #127,d0
Blt.s Ok
Sub #255,d0
Bra.s Ok
Negative
Cmp #-127,d0
Bgt.s Ok
Add #255,d0
Ok
Sub d0,Ypos
Bpl.s Not_too_small
Clr Ypos
Not_too_small
Cmp #200-Length,Ypos
Blt.s Not_too_big
Move #199-Length,Ypos
Not_too_big
Move Last_posx(pc),d0
Move Joy0dat,d1
And #$ff,d1
Move d1,Last_posx
Sub d1,d0
Bmi.s Negative2
Cmp #127,d0
Blt.s Ok2
Sub #255,d0
Bra.s Ok2
Negative2
Cmp #-127,d0
Bgt.s Ok2
Add #255,d0
Ok2
Sub d0,Xpos
Bpl.s Not_too_small2
Clr Xpos
Not_too_small2
Cmp #320-Width*8,Xpos
Blt.s Not_too_big2
Move #319-Width*8,Xpos
Not_too_big2
Lea Xs(pc),a0
Lea Ys(pc),a1
Move Pointer(pc),d2
Move Xpos(pc),(a0,d2)
Move Ypos(pc),(a1,d2)
Rts
;--------- Bob routine ----------
Width = 6
Length = 31
Bob_pt Dc.l Bob_data
Msk_pt Dc.l Bob_mask
Bob_scr Dc.l $70000
Scr_width = 40
No_pln = 2 ;Number of screen bitplanes
;-- Put x,y coordinate in d0,d1 respectively
Bob_draw
Move d0,d2
Lsr #4,d0
Add d0,d0 ;Find which word to start drawing the bob on
Mulu #80,d1 ;Find the screenline to start
;drawing the bob
Add d1,d0
Move.l Bob_scr(pc),a0 ;Start of the screen
Lea (a0,d0),a0 ;a0 now has the first word to which
;we want to copy the bob
Bsr Blit_wait
Move.l a0,Bltdpth
Move.l a0,Bltcpth ;Ch.C reads the screen data, Ch A is
;masked with Ch.B, and the masked
;area copied onto Ch.C before being
;sent back to the screen.
Move.l Bob_pt(pc),Bltapth ;Ch.A is used for the bob data
Move.l Msk_pt(pc),Bltbpth ;Ch.B used for the mask,only A&B
;can be shifted remember
Move.l #$ffff0000,Bltafwm ;Mask out the last word from A
Clr Bltamod ;Move back a word
Clr Bltbmod
Move #Scr_width-Width,Bltcmod ;Move on to next screen
Move #Scr_width-Width,Bltdmod ;line
And #$0f,d2
Ror #4,d2
Move d2,d0
Swap d0
Move d2,d0 ;This gets the A-B shift value into
;the right place
Or.l #$fe20000,d0 ;Use all 4 channels and set the
;minterms for bob use.
Move.l d0,Bltcon0
Move #Length*No_pln*64+Width/2,Bltsize ;Blit the bob
Rts ;This bob routine is not particularly fast
;for instance in a demo you would create tables
;for x,y position conversions, also some of the
;blitter registers do not need to be changed
;when plotting a new bob, but as this is supposed
;to be a general bob routine I left these
;optimisations out. See the 196 bob source for
;an example of how far you can take this. Also
;I have not used double buffering which is
;essential for a large number of bobs.
Bob_clr
Move d0,d2
Lsr #4,d0
Add d0,d0
Mulu #80,d1
Add d1,d0
Move.l Bob_scr(pc),a0
Lea (a0,d0),a0
Bsr Blit_wait
Move.l a0,Bltdpth
Move #Scr_width-Width,Bltdmod
Clr Bltadat
Move.l #$1f00000,Bltcon0
Move #Length*No_pln*64+Width/2,Bltsize
Rts
;--------- Constants -----------
Grname Dc.b "graphics.library",0
Even
;--------- Variables -----------
Pointer Dc.w 0
Xpos Dc.w 144
Ypos Dc.w 84
Xs Dcb.w 64,144
Ys Dcb.w 64,84
;---------- Copperlists -----------
Clstart
Mov $4081,Diwstrt ;Define the screen window as
Mov $08c1,Diwstop ;320 x 200 starting on line 80
Mov $0038,Ddfstrt
Mov $00d0,Ddfstop
Mov 0,Bplcon1 ;No scrolling
Mov 0,Bplcon2 ;Clear bitplane/sprite priorities
Mov 40,Bpl1mod ;We want the bitplanes to be arranged
Mov 40,Bpl2mod ;side by side for faster bob plotting
Mov 0,Bpl1ptl ;Set the start of the screen
Mov 7,Bpl1pth ;memory (must be placed in a
Mov 40,Bpl2ptl ;copperlist as it needs to be
Mov 7,Bpl2pth ;set every frame)
Mov $2200,Bplcon0 ;We want a 2 Bitplane, single playfield
;screen
Mov $000,Color00 ;Black background
Mov $00f,Color01 ;Shades of blue for the balls
Mov $00c,Color02
Mov $008,Color03
Wait 254,255 ;Wait for an impossible position
;tells the copper, this is the end
;of the copperlist
;-------------- Binaries ---------------
Bob_data
Incbin Binary/Bob
Bob_mask
Dcb.b No_pln*Width*Length,0